using System;
using System.IO;
using System.Linq;
using Microsoft.WowAddonStudio.FrameXml.Design.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests.Inheritance
{
	[TestFixture]
	public class PropertyInheritanceTest : FrameXmlControlTestBase
	{
		private FrameXmlSerializer serializer;

		#region SetUp / TearDown

		/// <summary>
		/// Tests the fixture set up.
		/// </summary>
		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			serializer = new FileFrameXmlSerializer(TestXmlFileName);
		}

		/// <summary>
		/// Sets up.
		/// </summary>
		[SetUp]
		public override void SetUp()
		{
			base.SetUp();
			if (File.Exists(TestXmlFileName)) File.Delete(TestXmlFileName);
			RegisterWowTocFile();
		}

		/// <summary>
		/// Tears down.
		/// </summary>
		[TearDown]
		public override void TearDown()
		{
			base.TearDown();
			if (File.Exists(TestXmlFileName)) File.Delete(TestXmlFileName);
		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_InheritedFrameWithValueChanged()
		{
			InitializeUi("Data/Inheritance/InheritedFrame.xml");


			var frameControl = UiControl.Controls.
				OfType<FrameControl>().FirstOrDefault(frame =>
				                                      	{
															Assert.IsNotNull(frame.LayoutFrame);
															return frame.LayoutFrame.Name == "Frame2";
				                                      	});

			Assert.IsNotNull(frameControl);

			Assert.IsNotNull(frameControl.LayoutFrame);

			Console.WriteLine(((Frame)frameControl.LayoutFrame).TopLevel);

			((Frame) frameControl.LayoutFrame).TopLevel = false;

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			WriteControls(UiControl);

			AssertTextLines("$parent");
		}

		#endregion
	}
}